#ifndef OLED_TASK_H
#define OLED_TASK_H

#include "main.h"
#include "cmsis_os.h"

#include "oled.h"
#include "flash_control.h"
#include "configs.h"
#include "mat_keyboard.h"

#define MENU_MAIN_INFO 						0x00
#define MENU_ROBOT_CONFIG					0x01
#define MENU_TOTAL_MENU						0x02

#define MAX_ID_NUM								0x02
#define MAX_MENU_NUM							0x07
#define MAX_SHOW_LINE_ON_TIME 		0x06



#define KEY_DOWN 									key_state.key_state[9]
#define KEY_DOWN_USE							key_state.keylocked_if[9]
#define KEY_DOWN_LOCK							key_state.keylocked_if[9]=1
#define KEY_UP  						 			key_state.key_state[1]
#define KEY_UP_USE								key_state.keylocked_if[1]
#define KEY_UP_LOCK								key_state.keylocked_if[1]=1
#define KEY_RIGHT 								key_state.key_state[6]
#define KEY_RIGHT_USE							key_state.keylocked_if[6]
#define KEY_RIGHT_LOCK						key_state.keylocked_if[6]=1			
#define KEY_LEFT 									key_state.key_state[4]
#define KEY_LEFT_USE							key_state.keylocked_if[4]
#define KEY_LEFT_LOCK							key_state.keylocked_if[4]=1
#define KEY_MID 									key_state.key_state[5]
#define KEY_MID_USE								key_state.keylocked_if[5]
#define KEY_MID_LOCK							key_state.keylocked_if[5]=1			
#define KEY_ENTER 								key_state.key_state[11]
#define KEY_ENTER_USE							key_state.keylocked_if[11]
#define KEY_ENTER_LOCK						key_state.keylocked_if[11]=1
#define KEY_SETTING 							key_state.key_state[7]
#define KEY_SETTING_USE						key_state.keylocked_if[7]
#define KEY_SETTING_LOCK					key_state.keylocked_if[7]=1				
#define KEY_ESCAPE 								key_state.key_state[3]
#define KEY_ESCAPE_USE						key_state.keylocked_if[3]
#define KEY_ESCAPE_LOCK						key_state.keylocked_if[3]=1			

typedef struct{
    Bool update_data_if;
    uint16_t file_id;
    File_Type type;
    uint8_t file_name[8];
    uint8_t file_namelen;
    uint8_t file_read_to_show[126];
    uint8_t oled_each_line_str_num[6];//each_show_line_num+total_line
    uint32_t total_read_len;
    File_operate_t file_operate;
}File_read_data_t;

typedef struct{
	uint8_t menu_name_show[12];
	uint8_t menu_name_len;
	uint8_t menu_pos;
}menu_package_t;

typedef struct{
  uint8_t oled_menu_id;
	menu_package_t oled_menu_list[MAX_ID_NUM][MAX_MENU_NUM];
	uint8_t oled_menu_list_num[MAX_ID_NUM];
	Bool button_sure_to_choose;
	Bool show_state;
	uint16_t sure_cnt;
	int8_t oled_up_pos_on_oled;
	int8_t oled_mouse_pos_on_oled;
	int8_t oled_mouse_pos_in_list;
	File_read_data_t file_read;
}oled_menu_t;


extern oled_menu_t oled_menu;

void oled_task(void const * argument);
void oled_menu_init(void);
void key_irq_handle(void);
void main_menu_key_irq(void);
void menu_robot_config_key_irq(void);
void menu_total_menu_key_irq(void);
void oled_menu_add(uint8_t* menu_name,uint8_t menu_name_len,uint8_t menu_id_belong);
void get_file_list_from_flash(uint8_t id_belong);

#endif
